
class SearchEngine {
  findCheaperHotel (budgets) {
    const budgetOrderly = this.sortByBudget(budgets)
    return this.getFirstHotel(budgetOrderly)
  }

  sortByBudget (budgets) {
    return budgets.sort((a, b) => {
      if (a.budget === b.budget) {
        return a.rating < b.rating
      }
      return parseFloat(a.budget) - parseFloat(b.budget)
    })
  }

  getFirstHotel (budgetOrderly) {
    return budgetOrderly.shift()
  }
}

module.exports = SearchEngine
